﻿@model WaiGaoQiaoWeb.Models.FundsOperatingTypeVM
@{
    ViewBag.Title = "FundsOperatingTypeIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    <script type="text/javascript" language="javascript">
        var maiheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth - 3; // 减去边框和左边的宽度
        var gh = maiheight - 213;
        $(document).ready(function () {
            var option = {
                height: maiheight - 80,
                width: $(document).width(),
                url: '@Url.Action("GetFundsOperatingTypeList")', // 参数要放在）括号的外面
                dataType: 'json',
                colModel: [
                    { display: '编号', name: 'DepositTypeID', width: 100, sortable: false, hide: false, align: 'left', iskey: true },
                    { display: '名称', name: 'DepositName', width: 200, sortable: false, hide: false, align: 'left' },
					{ display: '类别', name: 'AccountName', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '使用中', name: 'bUseName', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '是否显示', name: 'bShowName', width: 100, sortable: false, hide: false, align: 'left' }
				],
                buttons: [
                            { name: 'Add', displayname: "新增类别", title: "新增类别", bclass: 'add', onpress: toolbarItemAdd_onclick },
                            { name: 'Delete', displayname: "删除类别", title: "删除类别", bclass: 'delete', onpress: toolbarItemDel_onclick },
                            { name: 'Edit', displayname: "修改类别", title: "修改类别", bclass: 'edit', onpress: toolbarItemEdit_onclick },
							{ separator: true }
						 ],
                title: false,
                singleselected: false,
                usepager: true,
                resizable: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 20, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                rowbinddata: true,
                hideOnSubmit: true, //隐藏提交  
                autoload: true
            };
            $("#FundsOperatingTypeList").flexigrid(option);
            function toolbarItemAdd_onclick(cmd, grid) {
                OpenModelWindow('@Url.Action("AddFundsOperatingType")',
                                   { width: 450, height: 300, caption: "新增类别", onclose: refresh });
            }  // end of toolbarItemAdd_onclick

            function toolbarItemEdit_onclick(cmd, grid) {
                var items = $("#FundsOperatingTypeList").getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要编辑的类别!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (items.length > 1) {
                    showLoadingMsg("只能选择一个要编辑的类别!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                var ID = items[0][0];
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("SelFundsOperatingTypeEdit")',
                    data: { ID: ID },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data >0) {
                            showLoadingMsg("系统保留项不能编辑!", { left: 400, top: 6 }, true, 3000);
                        }
                        else
                        {
                            OpenModelWindow('@Url.Action("EditFundsOperatingType")?id=' + ID,
                            { width: 450, height: 300, caption: "修改类别", onclose: refresh });
                        }
                    },
                });
            }
            function toolbarItemDel_onclick(cmd, grid) {
                var items = $("#FundsOperatingTypeList").getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的类别!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除类别吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var ID = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteFundsOperatingType")',
                        data: { ID: ID },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data == "-2") {
                                showLoadingMsg("系统保留项不能删除!", { left: 400, top: 6 }, true, 3000);
                                return;
                            }
                            if (data) {
                                rowcount = rowcount + data;
                            }
                        },
                        error: function () { }
                    });
                }
                refreshGrid();
                showLoadingMsg("共有" + rowcount.toString() + "个类别被删除!", { left: 400, top: 6 }, true, 3000);
            }
            function refreshGrid() {
                $("#FundsOperatingTypeList").flexReload();
            }
            function refresh() {
                showLoadingMsg("保存成功", { left: 200, top: 6 }, true, 3000);
                $("#FundsOperatingTypeList").flexReload();
            }
        });    //end document ready() 
    </script>
}
<div id="container_sx">
    <div id="mainContent">
        <table id="FundsOperatingTypeList" style="display: none;">
        </table>
    </div>
</div>
